#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMenu>
#include <QDebug>
#include "wizard.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenu* fileMenu = new QMenu(this);
    QMenu* setMenu = new QMenu(this);

    fileMenu->setTitle("文件(&F)");
    setMenu->setTitle("设置(&S)");

    this->menuBar()->addMenu(fileMenu);
    this->menuBar()->addMenu(setMenu);

    // 添加菜单项
    QAction* createPro = new QAction("创建项目");
    createPro->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));


    createPro->setIcon(QIcon(":/icon/createpro.png"));  // 设置图标

    QAction* openPro = new QAction("打开项目");
    openPro->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
    openPro->setIcon(QIcon(":/icon/openpro.png"));


    QAction* setMusic = new QAction("设置音乐");
    setMusic->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
    setMusic->setIcon(QIcon(":/icon/music.png"));

    fileMenu->addAction(createPro);
    fileMenu->addAction(openPro);
    setMenu->addAction(setMusic);

    // 处理信号函数
    connect(createPro, &QAction::triggered, this, &MainWindow::handleCreatePro);
    connect(openPro, &QAction::triggered, this, &MainWindow::handleOpenPro);


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handleCreatePro(bool)
{
    qDebug() <<"创建项目";
    Wizard wizard(this);

    wizard.setWindowTitle("创建项目");

    auto* page = wizard.page(0);    // 拿到第一页
    page->setTitle("设置项目配置");

    // 连接信号和槽，把项目配置传回来 todo...


    wizard.show();
    wizard.exec();

    //


}

void MainWindow::handleOpenPro(bool)
{
    qDebug() << "打开项目";
}
